package es.deusto.tralala.gateway;

import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;

import es.deusto.tralala.authentication.*;
import es.deusto.tralala.rmi.server.ITralalaFacade;

public class Gateway implements IGateway {
private IAuthentificationServer service;
	
	public Gateway(String name){
		try {
			service = new AuthentificationServer();
			Naming.rebind(name, service);
		} catch (Exception e) {
			System.err.println("- Exception running the client: " + e.getMessage());
			e.printStackTrace();
		}
		
	}
	
	@Override
	public boolean login(String user, String pass) throws RemoteException {
		try {
			return service.login(user, pass);
		} catch (Exception e) {
			System.err.println("- Exception running the client: " + e.getMessage());
			e.printStackTrace();
		}
		return false; 
	}
	
	public void main2 (String[] args) {
		if (args.length != 3) {
			System.out.println("uso: java [policy] [codebase] cliente.Cliente [host] [port] [server]");
			System.exit(0);
		}

		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new RMISecurityManager());
		}

		try {
			System.out.println(service.login("user1", "user"));
			System.out.println("-LLEGO HASTA AQUI-");
		} catch (Exception e) {
			System.err.println("- Exception running the client: " + e.getMessage());
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		Gateway gat = new Gateway("AuthServer");
		gat.main2(args);
	}
}


